

project(core)

find_package(Qt5 COMPONENTS Gui REQUIRED)

file(GLOB_RECURSE SRCS CONFIGURE_DEPENDS ./*.cpp ./*.cc ./*.mm ./*.c)
source_group_by_dir(SRCS)

if (WINDOWS)
list(REMOVE_ITEM SRCS ${CMAKE_CURRENT_SOURCE_DIR}/./strings/stringconv_posix.cpp
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/atomic32_mac.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/atomic32_posix.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/timer_oc.mm
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/timer_posix.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/event_posix.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/thread_posix.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/condition_variable_posix.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/critical_section_posix.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/rw_lock_posix.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/trace_posix.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./sync/lock.mm)
elseif (LINUX)
list(REMOVE_ITEM SRCS ${CMAKE_CURRENT_SOURCE_DIR}/./system/atomic32_mac.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/timer_oc.mm
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/timer_win.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/atomic32_win.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/critical_section_win.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/thread_win.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/condition_variable_native_win.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/condition_variable_event_win.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/trace_win.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/rw_lock_win.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/event_win.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./sync/lock.mm)
elseif (MACOS)
list(REMOVE_ITEM SRCS ${CMAKE_CURRENT_SOURCE_DIR}/./system/atomic32_posix.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/timer_posix.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/timer_win.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/atomic32_win.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/critical_section_win.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/thread_win.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/condition_variable_native_win.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/condition_variable_event_win.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/trace_win.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/rw_lock_win.cc
                      ${CMAKE_CURRENT_SOURCE_DIR}/./system/event_win.cc)
endif()

add_library(${PROJECT_NAME} SHARED
     ${SRCS}
     res/core.qrc
)

if (WINDOWS)
    add_compile_options(/wd4251)
    target_link_libraries(${PROJECT_NAME} PRIVATE Qt::Gui)
    target_compile_options(${PROJECT_NAME} PRIVATE -DS_CORE_DLL)
elseif (LINUX)
    target_link_libraries(${PROJECT_NAME} PRIVATE Qt::Gui rt)
    target_compile_options(${PROJECT_NAME} PRIVATE -DS_CORE_DLL -DCCORE_LINUX)
elseif (MACOS)
    target_link_libraries(${PROJECT_NAME} PRIVATE Qt::Gui iconv "-framework Cocoa -framework AppKit -framework CoreData -framework Foundation")
    target_compile_options(${PROJECT_NAME} PRIVATE -DS_CORE_DLL -DCCORE_MAC -DCCORE_CLOCK_TYPE_REALTIME)
endif()

